
#include "../libpatches.h"
#include "phasor.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

static void module_phasor_processor(module m);

void module_phasor_initializer(module m) {
	make_inputs(m, 2);
	make_outputs(m, 1);

	m->input_names[0] = "frequency";
	m->input_names[1] = "phase"; 

	make_buffer(m, 1);

	m->output_names[0] = "out";

	m->processor = module_phasor_processor;
}

static void module_phasor_processor(module m) {
	extern int sampling_rate;
	output o = m->outputs[0];

	/*
	fprintf(stderr, "processing phasor\n");
	*/

	input freq = m->inputs[0];
	input phase = m->inputs[1];
	sample * s = m->buffer;
	sample p = *s;

	*s += **freq / sampling_rate;
	*s -= floor(*s);

	*o = p;

	*o += **phase;
	*o -= floor(*o);

}

